package com.webbei.HAO.action;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Random;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.webbei.HAO.service.ChSer;
import com.webbei.myCustom.action.MyUtil;

public class Update extends ActionSupport {

	private ChSer ser;

	private String id;
	private String username;
	private String realname;
	private File file1;
	private String sex;

	private String provaice;
	private String city;
	private String area;

	private String address;
	private String telphone;
	private String phone1;
	private String phone2;
	private String userface;
	private String realpath;
	private String file1ContentType;
	
	private String personalSign;
	public String execute() {
		System.out.println("进入UpdateAction");
		System.out.println("个人信息："+personalSign);
		String username = (String) ServletActionContext.getContext()
				.getSession().get("username");
		provaice = provaice.substring(6);
		city = city.substring(7);
		String path = ServletActionContext.getServletContext().getRealPath("/")
				+ "img/resources/webbeiUserInfo/" + username + "/userTouxiang";
		MyUtil.delete(path);
		if (file1 != null) {
			String[] t = file1ContentType.split("/");
			String picname = String.valueOf((new Date().getTime()))
					+ String.valueOf(new Random().nextInt(3)) + "."
					+ t[t.length - 1];
			File savefile = new File(new File(path), picname);
			realpath = "img/resources/webbeiUserInfo/" + username
					+ "/userTouxiang/" + picname;
			try {
				FileUtils.copyFile(file1, savefile);
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			realpath = userface;
		}

		int userid = Integer.parseInt(id);
		ser.update(userid, username, realname, realpath, sex, provaice, city,
				address, area, telphone, phone1 + "-" + phone2);
		ser.updatePersonalSign(username,personalSign);
		return SUCCESS;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	public String getRealpath() {
		return realpath;
	}

	public void setRealpath(String realpath) {
		this.realpath = realpath;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getUserface() {
		return userface;
	}

	public void setUserface(String userface) {
		this.userface = userface;
	}

	public String getProvaice() {
		return provaice;
	}

	public void setProvaice(String provaice) {
		this.provaice = provaice;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getTelphone() {
		return telphone;
	}

	public void setTelphone(String telphone) {
		this.telphone = telphone;
	}

	public String getPhone1() {
		return phone1;
	}

	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}

	public String getPhone2() {
		return phone2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	public ChSer getSer() {
		return ser;
	}

	public void setSer(ChSer ser) {
		this.ser = ser;
	}

	public File getFile1() {
		return file1;
	}

	public void setFile1(File file1) {
		this.file1 = file1;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getFile1ContentType() {
		return file1ContentType;
	}

	public void setFile1ContentType(String file1ContentType) {
		this.file1ContentType = file1ContentType;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPersonalSign() {
		return personalSign;
	}

	public void setPersonalSign(String personalSign) {
		this.personalSign = personalSign;
	}

}
